﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Drawing;

public partial class rdaochu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        string sqlStr = "select RID as 编号 , RGID as 货品编号,GTYPEName as 类别,GCHName as 名称,GXinhao as 型号,GBrand as 品牌, RWID as 仓库编号,RQuantity as 数量,RHandler as 收货人,RDate as 日期,RifAOG as 出库确认,RComfirmer as 确认人,RComfirmedDate as 确认日期,bianhao as 项目编号,PName as 项目名 from [Projects],[RecordsIN],[Goods] where RecordsIN.RGID=Goods.GID and RecordsIN.RPID=Projects.PID";
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        //GridView1.DataKeyNames = new string[] { "货品编号" };
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();
        myConn.Close();
        Response.ClearContent();
        //Response.BufferOutput = true;
        ////设定输出的字符集
        //Response.Charset = "GB2312";
        //假定导出的文件名为FileName.xls
        Response.AppendHeader("Content-Disposition", "attachment;filename=入库货物.xls");
        //Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        //设置导出文件的格式
        Response.ContentType = "application/ms-excel";
        ////关闭ViewState
        //EnableViewState = false;
        //System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
        //System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
        //System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.RenderControl(htw);
        //把HTML写回浏览器
        Response.Write(sw.ToString());
        Response.End();
    }

    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }

    public override void VerifyRenderingInServerForm(Control control)
    {

    }
}